<root xmlns="http://www.w3.org/1999/xhtml"
      xmlns:py="http://genshi.edgewall.org/"
      xmlns:xi="http://www.w3.org/2001/XInclude">
    <xi:include href="rds.html" />

<?python
     import datetime
     import time
     from genshi.input import XML, HTML
     from mnemoply.common_knowledge import day_captions
     from mnemoply import model

     day_of_week = range(1, 8)

     time_format = "%Y-%m-%d"
     start_date = datetime.datetime.fromtimestamp(time.mktime(time.strptime(start_date, time_format))).date()
     office = model.Office.get(ids[0])
?>

<report>
            <office py:content="office.name" />
            <classroom py:for="classroom in model.Classroom.selectBy(office=office)" py:strip="True">
                <row py:for="session in range(1, 6)">
                    <classroom py:content="classroom.roomNumber" />
                    <session py:content="session" />

                    <loop py:for="i in day_of_week" py:strip="True">
                        <?python
                             lessons = classroom.getLessonsByDate(start_date + datetime.timedelta(days=i))

                             lesson = None
                             try:
                                 all_lessons_for_session = [l for l in lessons if l.group.session == session]
                                 lesson = all_lessons_for_session[0]
                                 if len(all_lessons_for_session) > 1:
                                     cell_style = "more_one"
                             except:
                                 pass

                             if lesson is not None:
                                 content = '<day%d>\r\n' % i + \
                                     lesson.getStartTimeStr() + \
                                     "-" + \
                                     lesson.getEndTimeStr() + "\r\n" + \
                                     lesson.group.getShortName() + "\r\n" + \
                                     "%d" % lesson.group.cacheStudents + "\r\n" + \
                                     lesson.group.teacher.title + "\r\n" + \
                                     "</day%d>" % i
                                 xml = XML(content)
                             else:
                                 xml = XML("<day%d></day%d>" % (i, i))
                        ?>
                        ${xml}
                    </loop>
                </row>
            </classroom>
</report>

</root>
